function goBack(){ 
	if($(".swiper-shadow").css("display")=="block"){
    $(".swiper-shadow").hide();
  }else if($("#merchanturl").css("display")=="block"){
    $("#merchanturl").hide();
  }else{
//   if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {             
//          window.location.href = window.document.referrer;
//  } else { 
      window.history.go("-1"); 
//  }
  }
}

function fakegoBack(){ 
  if($(".swiper-shadow").css("display")=="block"){
    $(".swiper-shadow").hide();
  }else{
    window.location.href = window.document.referrer;
  }
}

function jsnativelogin(){
	var ua = navigator.userAgent.toLowerCase();	
	if (ua.indexOf("iphone")>-1) {
		location.href = 'ios://popVC';
//	    window.webkit.messageHandlers.AppHandler.postMessage('popVC');
	} else if (ua.indexOf("android")>-1) {
		    window.ocm.Jstologin();	
	}
}

function jsnativeloginout(){
	$.post(
		"/api/AppUser/loginOut/","",function(data){
			var ua = navigator.userAgent.toLowerCase();	
			if (ua.indexOf("iphone")>-1) {
				location.href = 'ios://logout';
		//	    window.webkit.messageHandlers.AppHandler.postMessage('popVC');
			} else if (ua.indexOf("android")>-1) {
				    window.ocm.Jstologinout();	
			}
		},"json"
	)
}

function ajaxStrToObj(data){
	 var start = data.indexOf(">");  
     if(start != -1) {  
       var end = data.indexOf("<", start + 1);  
       if(end != -1) {  
         data = data.substring(start + 1, end);  
        }  
     }  
     eval( "data = " + data);
	return data;
}

var loader = (function(){
	var lo = function(){}
	var imgurl = "";
	var load=null;
	lo.prototype.init = function(_url){
		imgurl = _url;
		load = document.getElementById("loading");
		if(!load){
			load = document.createElement("div");
			load.id = "loading";
			var img = document.createElement("img");
			load.style.display="none";
			load.style.position = "fixed";
			load.style.top = 0;
			load.style.left = 0;
			load.style.width = "100%";
			load.style.height = "100%";
			load.style.zIndex = 9999;
			load.style.background = "rgba(0,0,0,0.8)";
			img.src = imgurl;
			img.style.display = "block";
			img.style.margin = "50% auto";
			load.appendChild(img);
			document.body.appendChild(load);
		}
	}
	
	lo.prototype.show = function (){
		load.style.display= "block";
	}
	lo.prototype.hide = function (){
		load.style.display= "none";
	}
	return lo;	
})();

function imgerror(obj){
	obj.src = "/themes/simplebootx_mobile/Public/img/user/defaulthead.png";
}
function IsURL(str_url){
    var strRegex = "^((https|http|ftp|rtsp|mms)[1]://)"
    + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
    + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
    + "|" // 允许IP和DOMAIN（域名）
    + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
    + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
    + "[a-z]{2,6})" // first level domain- .com or .museum
    + "(:[0-9]{1,4})?" // 端口- :80
    + "((/?)|" // a slash isn't required if there is no file name
    + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
    var re=new RegExp(strRegex);
    //re.test()
    if (re.test(str_url)){
        return (true);
    }else{
        return (false);
    }
}

var countdown = (function(){
	var _cd = function(){}
	_cd.prototype.init = function(change_obj_id){
		cdobj = document.getElementById(change_obj_id);
	}
	var cdnum = 60;
	var cdobj = null;
	var time=null;
	var _cding = false;
	_cd.prototype.start = function(fuc){
//		if(!_cding){
//			_cding = true;
			cdobj.disabled="true";
			if(fuc!=null)fuc();
			dec();
//		}
	}
	
	function dec(){
		if(cdnum==0){
			clearTimeout(time);
			cdobj.innerText="获取验证码";
			cdnum = 60;
			_cding  = false;
			cdobj.disabled="";
			return;
		}
		cdobj.innerText = cdnum;
		cdnum--;
		time = setTimeout(dec,1000);
	}
	return _cd;
})();
var toast = {
	init:function(){
		var tmp = document.getElementById("dialog_toast");
		if(tmp)this.obj = tmp;
		else{
			var _height = "40px";
			var _width ="200px";
			var toast= document.createElement("div");
			var toastbg = document.createElement("div");
			var _text = document.createElement("p");
			toast.id= 'dialog_toast';
			toast.style.width= "100%";
			toast.style.textAlign = "center";
			toast.style.display ="none";
			toast.style.opacity = "0";
			toast.style.zIndex = "999";
			toast.style.position = "fixed";
			toast.style.bottom = "80px";
			toastbg.style.borderRadius = "5px";
			toastbg.style.background = "rgba(0,0,0,0.5)";
			toastbg.style.margin = "auto"
			toastbg.style.width = _width;
			toastbg.style.minHeight = _height;
			_text.style.padding = "15px 0";
			_text.style.fontSize = "14px";
			_text.style.color = "white";
			_text.style.textAlign= "center";
//			_text.style.lineHeight= _height;
			_text.style.width = "100%";
//			_text.style.height = _height;
			_text.innerText = " ";
			toastbg.appendChild(_text);
			toast.appendChild(toastbg);
			document.getElementsByTagName("body")[0].appendChild(toast);
			this.obj= toast;
			this.txt =_text; 
		}
	},
	show:function(msg,duration){
		if(!duration)duration = 2000;
		var o = this.obj;
		this.txt.innerText = msg;
		o.style.display="block";
		o.style.opacity = "1";
		setTimeout(function(){
			fade(duration);
		},1000);
		
		function fade(duration){
			var opac = 0.99;
			var dur = Math.floor(duration/100);
			var step = (opac/dur).toFixed(2);
			this.step = step;
			fadeOutAnimal();
		}
		function fadeOutAnimal(){
			var opac = o.style.opacity;
			if(opac<=0.1){
				o.style.opacity = 0;
				o.style.display = "none";
				clearTimeout(this.time);
				return;
			}else{
				o.style.opacity = opac - step;
			}
			this.time = setTimeout(fadeOutAnimal,50);
		}
	}
}
var dialog = (function(){
	var dg = function(){}
	var partn = null;
	var _okcb = null;
	var btn = document.getElementsByClassName("dlg-btn")[0];
	var closebtn = document.getElementsByClassName("dlg-close")[0];
	dg.prototype.init = function(id,okcallback){
		partn = document.getElementById(id);
		_okcb = okcallback;
		eventinit();
	}
	dg.prototype.show = function(){
		show();
	}
	var eventinit = function(){
		btn.onclick = function(){
			ok();
		}
		if(closebtn)closebtn.onclick = function(){
			close();	
		}
	}
	var ok = function(){
		if(_okcb!=null)_okcb();
		close();
	}
	var show = function(){
		partn.style.display = "block";
	}
	var close = function(){
		partn.style.display = "none";
	}
	return dg;
})();